#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/types_c.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/time.h>
#include <iconv.h>
#include <sstream>
#include <string>
#include <string.h>

using namespace std;
using namespace cv;


int main()
{
    string gsurl = "rtspsrc location=rtsp://admin:ubo12345@192.168.1.100:554/h264/ch1/main/av_stream latency=200 ! rtph264depay ! h264parse ! omxh264dec !nvvidconv ! video/x-raw, width=(int)1280, height=(int)760, format=(string)BGRx ! videoconvert ! appsink sync=false";  
    VideoCapture cap = VideoCapture(gsurl,cv::CAP_GSTREAMER);
    if(!cap.isOpened())
    {
        std::cout<<"cannot open captrue..."<<std::endl;
        return 0;
    }

    int fps = cap.get(5);
    cout<<"fps:"<<fps<<endl;
    Mat frame;
    bool readreturn = false;
    while(1)
    {  
        readreturn = cap.read(frame);

        imshow("RTSP",frame);
        if ( cv::waitKey(10) == 27) 
        {
            cout << "Esc key is pressed by user" << endl;
            break;
        }
    }

    cap.release();
    return 0;
}
//g++ test_gstream.cpp `pkg-config --cflags --libs opencv4` --std=c++11

